

public class CordImpl implements Cord 
{
	
	private int x;
	
	private int y;
	
	public CordImpl( int x, int y )
	{
		this.x = x;
		this.y = y;
	}
	
	public CordImpl( short coords )
	{
//		this.x = coords & 0x00FF;
//		this.y = (coords & 0xFF00) >> 8;
		this.x = getXFromCords(coords);
		this.y = getYFromCords(coords);
	}
	
	public short getCords()
	{
//		return (short) ( x | ( y << 8 ) );
//		return (short) x;
		return getCoordsFromXY(x, y);
	}
	
	public static short getCoordsFromXY( int x, int y )
	{
		return (short) ( x | ( y << 8 ) );
	}
		
	public static int getXFromCords( short coords )
	{
		return (coords & 0x00FF);
	}
	
	public static int getYFromCords( short coords )
	{
		return ((coords & 0xFF00) >> 8);
	}

	@Override
	public Cord cloneCord()
	{
		return new CordImpl(x,y);
	}

	@Override
	public Cord doNewMove(Move.Direction direction) 
	{
		return new CordImpl( getX() + direction.getXDiff(), getY() + direction.getYDiff() );
	}
	@Override
	public boolean equals(Object obj) 
	{
		return equalsCord((Cord) obj);
	}
	
	@Override
	public boolean equalsCord( Cord ref )
	{
		return ( x == ref.getX() ) && ( y == ref.getY() );
	}

	@Override
	public boolean equalsMove( Move move )
	{
		return ( x == move.getX() ) && ( y == move.getY() );
	}

	@Override
	public int getX() 
	{
		return x;
	}
	
	@Override
	public int getY() 
	{
		return y;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + x;
		result = prime * result + y;
		return result;
	}

	@Override
	public String toString()
	{
		return "x="+x +", y="+y;
	}

	@Override
	public void update(int x, int y) 
	{
		this.x = x;
		this.y = y;
	}
}
